package boot.spring.service.impl;

import boot.spring.entity.Student;
import boot.spring.entity.Tracking;
import boot.spring.mapper.StudentMapper;
import boot.spring.mapper.TrackingMapper;
import boot.spring.mapper.UsersMapper;
import boot.spring.service.MystudentsService;
import boot.spring.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class MystudentsServiceImpl implements MystudentsService {
    /*注入学生表的持久层*/
    @Autowired
    private StudentMapper studentMapper;

    /*注入跟踪日记表的持久层*/
    @Autowired
    private TrackingMapper trackingMapper;

    /*注入用户表*/
    @Autowired
    private UsersMapper usersMapper;

    Result r=new Result();
    @Override/*分页多条件查询当前咨询师的学生*/
    public Result ListSerUidStuAll(Integer page,Integer limit,Integer uid,String stuname,String ifPay,String qq,String sex) {
        Map<String,Object> map=new HashMap<>();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("uid",uid);
        map.put("stuname",stuname);
        map.put("ifPay",ifPay);
        map.put("qq",qq);
        map.put("sex",sex);
        List<Student> list=studentMapper.ListMapUidStuAll(map);
        Integer count=studentMapper.countuidstu(map);
        if(list.size()>0){
            r=new Result(0,"请求成功",count,list);
        }else{
            r=new Result(1,"请求失败");
        }
        return r;
    }

    @Override/*新增一条跟踪日志*/
    public Result GetSerTraStuAdd(Tracking add) {
        Integer traadd=trackingMapper.TraMapAdd(add);
        if(traadd>0){
            r=new Result(0,"新增成功");
            /*当新增成功时同时把当前用户的跟踪次数加1*/
            Integer a=usersMapper.UserResultsUp(add.getUid());
        }else{
            r=new Result(1,"新增失败");
        }
        return r;
    }

    @Override
    public int getCount(Map<String, Object> map) {
        // TODO Auto-generated method stub
        return trackingMapper.getCount(map);
    }

    @Override
    public List<Tracking> Looks(Map<String, Object> map) {
        // TODO Auto-generated method stub
        return trackingMapper.Looks(map);
    }

    @Override
    public int Addstu(Map<String, Object> map) {
        // TODO Auto-generated method stub
        return studentMapper.Addstu(map);
    }

    @Override
    public List<Student> getAll(Map<String, Object> map) {
        // TODO Auto-generated method stub
        return studentMapper.getAll(map);
    }

    @Override
    public int getwangluoCount(Map<String, Object> map) {
        // TODO Auto-generated method stub
        return studentMapper.getCount(map);
    }
}
